//
//  BeautyListView.m
//  BeautyList
//
//  Created by 李良林 on 2020/12/6.
//  Copyright © 2020 李良林. All rights reserved.
//

#import "BeautyListView.h"
#import "BeautyListModel.h"
#import "Base64.h"

//色值
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b) RGBA(r,g,b,1.0f)
//#import ""

@interface BeautyListView()
@property (nonatomic,  strong) UIVisualEffectView *blurView;
@property (nonatomic,  strong) UILabel *label;
@property (nonatomic,  assign) CGPoint  point;
@property (nonatomic,  assign) double *count;
@end

@implementation BeautyListView

#pragma mark -------------------------------------视图-------------------------------------------

- (instancetype)initWithFrame:(CGRect)frame config:(YMTableViewConfig *)config
{
    self = [super initWithFrame:frame config:config];
    if (self) {
        
        self.alpha = 0.85;
        self.layer.cornerRadius = 8;
        self.layer.masksToBounds = YES;
        
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        self.tableView.backgroundColor = RGBA(169, 169, 169, 0.8);
//        self.tableView.tableFooterView = self.label;
    
        self.tableView.separatorInset = UIEdgeInsetsZero;
        if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
            [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        }
        if ([self.tableView respondsToSelector:@selector(setLayoutManager:)]) {
            [self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 20, 0, 20)];
        }
        
        NSString *menuButtonBase64 = LOGConfig;
       
        NSData* data = [[NSData alloc] initWithBase64EncodedString:menuButtonBase64 options:0];
        UIImage* menuButtonImage = [UIImage imageWithData:data];
        
        
        self.image = menuButtonImage;
       
//        [self addSubview:self.blurView];
//        [self sendSubviewToBack:self.blurView];
        
        [self addGestureRecognizer: [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)]];
        
        [self setupData];
    }
    return self;
}

- (UIVisualEffectView *)blurView{
    if (!_blurView) {
        UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
        UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:blur];
        blurView.frame = self.bounds;
      
        
        blurView.layer.mask = ({
            UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:blurView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(20, 20)];
            CAShapeLayer *layer = [CAShapeLayer layer];
            layer.path = path.CGPath;
            layer;
        });
    }
    return _blurView;
}
//
- (void)setupData
{
    NSArray *array = @[@"木已成舟",@"破釜沉舟",@"翻云覆雨",@"逃跑计划",@"你好哇塞"];
    NSArray *opens = @[@1,@0,@0,@1,@1];
    NSArray *textFlied = @[@0,@1,@1,@0,@0];//这里 第几个功能需要是输入框 就写1 就行
    
    for (NSInteger i = 0; i < array.count; i++) {
        BeautyListModel *model = [[BeautyListModel alloc] init];
        model.title = array[i];
        model.Style = [opens[i] integerValue];
        model.textFlied = [textFlied[i] integerValue];
        [self.dataArray addObject:model];
    }
    
    [self.tableView reloadData];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    BeautyListModel *model = self.dataArray[indexPath.row];
    
    if (model.textFlied == 1) {
        
        [BeautyListModel textEvent:model.title open:model.textFlied];
        
    }
   
   
}
////上名称
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    UITableViewHeaderFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
//    if (!view) {
//        view = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"header"];
//        view.tintColor= [UIColor clearColor];
//        ((UITableViewHeaderFooterView *)view).backgroundView.backgroundColor = [UIColor clearColor];
//        view.textLabel.text = @"开挂很爽";
//        [view.textLabel setTextColor:[UIColor whiteColor]];
//    }
//
//    return view;
//}

- (void)panAction:(UIGestureRecognizer *)gesture
{
    CGPoint p = [gesture locationInView:gesture.view];
    self.center = CGPointMake(self.center.x + p.x - self.bounds.size.width * 0.5, self.center.y + p.y - self.bounds.size.height * 0.5);
}
////下名称
//- (UILabel *)label{
//    if (!_label) {
//        UILabel *label = [[UILabel alloc] init];
//        label.text = [NSString stringWithFormat:@"👉开挂很爽👈"];
//        label.textColor = [UIColor redColor];
//        label.font = [UIFont systemFontOfSize:16];
//        label.textAlignment = 1;
//        [label sizeToFit];
//        label.frame = CGRectMake(0, 0, 250, 22);
//        label.center = self.tableView.center;
//
//        _label = label;
//    }
//    return _label;
//}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
